home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_GTIME.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  7KB  |  157 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gtime - get time from window with gross validation 
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. ************
  17. * wn_gtime *
  18. ************
  19. */
  20.  
  21. /*
  22. ** wn_gtime(fun,frm,fld,wn,row,col,prmpt,atrib,fill,hrs,mins,secs,ubuff,hlpmsg,errmsg)
  23. **
  24. **    int        fun - fucntion code (SET || XEQ)
  25. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  26. **    int        fld - field # in form (actual || NFLD)
  27. **    (WINDOWPTR) wn - window pointer
  28. **    int        row - row in window where data input begins
  29. **    int        col - col in window where data input begins
  30. **    (char *) prmpt - field promt (call with NSTR for none)
  31. **    unsigned atrib - field (not prompt) atributes 
  32. **    char      fill - field fill character
  33. **    (int *)    hrs - pointer to int for month (0-24)
  34. **    (int *)   mins - pointer to int for day (0-59)
  35. **    (int *)   secs - pointer to int for year (0-59)
  36. **    (char *) ubuff - pointer to char array of 10 bytes for editing 
  37. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  38. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  39. **
  40. ** RETURNS:
  41. **
  42. **    HRS, MINS, and SECS via pointers.
  43. **
  44. **    NULL if error, else the non zero value returned from wn_input.
  45. **
  46. ** NOTES:
  47. **
  48. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  49. **          execution.  When called with SET, valid arguements for both
  50. **          "frm" and "fld" must be specfied.  frm is the field pointer
  51. **          returned from frmopn(), and fld is the field sequence number
  52. **          in the form for this field.  When called with XEQ frm must
  53. **          be NFRM and fld must NFLD.
  54. **
  55. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  56. **          data as it is entered.  Typical value is the length
  57. **          of the mask + 2 bytes (strlen(mask)+2).
  58. **
  59. **          On entry, the first byte of ubuff should be 
  60. **          a null, otherwise wn_input assumes there is valid
  61. **          data there and will enter edit mode.  This can be 
  62. **          handy if there is a need for prefilled but editable
  63. **          fields.  In actual pratice, wn_input uses this
  64. **          buffer for both initial character data entry and
  65. **          subsequent editing.
  66. **
  67. **          On return, ubuff contains the actual data entered in
  68. **          character format with fill and mask characters as
  69. **          spaces (e.g. "23 59 22").
  70. **
  71. **  Only basic reasonability checks are made.  Therefore, times like
  72. **  24:59:59 can be returned.
  73. **
  74. **  Calls wn_input to perform data entry.
  75. **
  76. **  Data must satisfy validation checks for function to return.
  77. */
  78.  
  79. wn_gtime(fun,frm,fld,wn,row,col,prmpt,atrib,fill,hours,mins,secs,ubuff,hlpmsg,errmsg)
  80. int fun;                                /* SET or XEQ */
  81. WIFORM frm;                             /* form pointer or NFRM */
  82. int fld;                                /* field number or NFLD */
  83. WINDOWPTR wn;                           /* window to use */
  84. int row, col;                           /* position of input field */
  85. char *prmpt;                            /* prompt string */
  86. unsigned atrib;                         /* data entry atribute */
  87. char fill;                              /* fill char */
  88. int *hours, *mins, *secs;               /* hours, mins, secs */
  89. char *ubuff;                            /* returns "hh:mm:ss" */
  90. char *hlpmsg, *errmsg;                  /* help & error messages */
  91. {
  92. int h, m, s;                            /* hours, mins, secs */
  93. char mbuf[10];                          /* local buffer */
  94. char *p;                                /* scratch */
  95. unsigned int r;                         /* sscanf return value */
  96. int rv;                                 /* return value */
  97. int eflg;                               /* error flag */
  98.  
  99.   if(fun != SET && fun != XEQ)          /* saftey check */
  100.     return(NULL);
  101.  
  102.   if(fun == SET) {                      /* set up */
  103.     if(frm[fld]->pself != (char *)frm[fld])
  104.       wns_ierr("wn_gtime");             /* die if memory is mangled */
  105.     frm[fld]->wn = wn;                  /* set window */
  106.     frm[fld]->row = row;                /* set row */
  107.     frm[fld]->col = col;                /* set col */
  108.     frm[fld]->prmpt = prmpt;            /* set prompt */
  109.     frm[fld]->atrib = atrib;            /* set attribute */
  110.     frm[fld]->fill = fill;              /* set fill character */
  111.     frm[fld]->fcode = GTIME;            /* function code */
  112.     frm[fld]->v1.vip = hours;           /* &hours */
  113.     frm[fld]->v2.vip = mins;            /* &mins */
  114.     frm[fld]->v3.vip = secs;            /* &secs */
  115.     frm[fld]->v4.vcp = ubuff;           /* &ubuff */
  116.     frm[fld]->v5.vcp = hlpmsg;          /* &hlpmsg */
  117.     frm[fld]->v6.vcp = errmsg;          /* &errmsg */
  118.     return(TRUE);
  119.   }
  120.  
  121. begin:
  122.   if(!(rv=wn_input(wn,row,col,prmpt,"##:##:##",fill,atrib,ubuff,hlpmsg))) {
  123.     *ubuff = NUL;                       /* load ubuff with a bad time */
  124.     return(NULL);                       /* indicate error */
  125.   }
  126.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  127.   if(wns_escape) return(rv);            /* escape pressed ?? */
  128.   strcpy(mbuf,ubuff);                   /* load my buffer */
  129.   p = mbuf;                             /* set pointer */
  130.   while (*p) {                          /* set up to pluck */
  131.     if(*p == ':')                       /* the colon */
  132.       *p = ' ';                         /* and stash a space */
  133.     p++;                                /* bump pointer */
  134.   }                                     /* continue till done */
  135.   r =  sscanf(mbuf, "%02d %02d %02d", &h, &m, &s);
  136.   if(r == EOF || r == 0) {              /* no data */
  137.     *hours = *mins = *secs = 0;         /* set em all to zip */
  138.     return(rv);                         /* and return */
  139.   }
  140.   eflg = FALSE;
  141.   if(r != 3) eflg = TRUE;               /* not enuf data */
  142.   if(h < 0 || h > 24) eflg = TRUE;      /* bad hour */
  143.   if(m < 0 || m > 59) eflg = TRUE;      /* bad min */
  144.   if(s < 0 || s > 59) eflg = TRUE;      /* bad sec */
  145.   if(eflg) {                            /* error ? */
  146.     wn_iemsg(errmsg);                   /* do error thing */
  147.     goto begin;                         /* and start over */
  148.   }
  149.   *hours = h;                           /* load user hours */
  150.   *mins = m;                            /* and mins */
  151.   *secs = s;                            /* and seconds */
  152.   return(rv);                           /* all is well.. in gross sense */
  153. }
  154.  
  155. /* End */
  156.  
  157.